package com.atguigu.democustomer230301.service.impl;

import com.atguigu.democustomer230301.bean.Customer;
import com.atguigu.democustomer230301.mapper.CustomerMapper;
import com.atguigu.democustomer230301.service.CustomerService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
@DS("demo")
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper,Customer> implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public String sayHello() {
        System.out.println("Service:111111");
        return "Hello SZ";
    }

    @Override
    public String getCustomerByName(String name) {
        Customer customer = customerMapper.selectCustomerByName(name);
        return "Customer:"+customer.toString();
    }

    @Override
    public String getCustomerById(String id) {
//        String sql = "select * from customer where id=" + id;

//        Map result = customerMapper.selectCustomerById(sql);
        Customer customer = customerMapper.selectById(id);
        return "Customer:"+customer;
    }

    @Override
    @DS("demo")
    public void saveCustomer(Customer customer) {
//        System.out.println("保存：" + customer);
        customerMapper.insertCustomer(customer);
    }
}
